#include "../../myrpc/RpcClient.h"
#include "../../myrpc/myrpccontroller.h"
#include "../../myrpc/myrpc.pb.h"
#include "ping.pb.h"
#include <thread>
#include "../../include/google/protobuf/stubs/callback.h"


void FooDone(myrpc::PingResponse *response, myrpc::MyRpcController*controller) {
	if (controller->Failed()) {
		printf("test 2 Rpc Failed : %s\n", controller->ErrorText().c_str());
	}
	else {
		printf("++++++ test 2 Rpc Response is %s\n", response->result().c_str());
	}

}


int main()
{	
	
	myrpc::RpcClient client;
	std::thread  th([=]() { 	client.Connect("127.0.0.1", 18888); });


	Sleep(10000);
	myrpc::PingService_Stub stub(&client);
	

	myrpc::MyRpcController*  Controller = new myrpc::MyRpcController;
	myrpc::PingRequest request;
	myrpc::PingResponse response;
	stub.Ping(Controller , &request , &response , google::protobuf::NewCallback(&FooDone, &response, Controller));

	myrpc::PingRequest request1;
	myrpc::PingResponse response1;
	stub.Ping(Controller, &request1, &response1, google::protobuf::NewCallback(&FooDone, &response1, Controller));
	return 0;
}